<?php

namespace app\admin\model\xilujob;

use app\admin\model\User;
use think\Model;
use traits\model\SoftDelete;

class PackageOrder extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'xilujob_package_order';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'pay_status_text',
        'paytime_text',
        'package_unit_text'
    ];
    

    
    public function getPayStatusList()
    {
        return ['0' => __('Pay_status 0'), '1' => __('Pay_status 1'), '2' => __('Pay_status 2')];
    }

    public function getPackageUnitList()
    {
        return ['1' => __('Package_unit 1'), '2' => __('Package_unit 2'), '3' => __('Package_unit 3')];
    }


    public function getPayStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['pay_status']) ? $data['pay_status'] : '');
        $list = $this->getPayStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPaytimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['paytime']) ? $data['paytime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getPackageUnitTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['package_unit']) ? $data['package_unit'] : '');
        $list = $this->getPackageUnitList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function user(){
        return $this->belongsTo(User::class,'user_id','id',[],'left')->setEagerlyType(0);
    }

    public function enterprise(){
        return $this->belongsTo(EnterpriseInfo::class,'company_id','company_id',[],'left')->setEagerlyType(0);
    }
}
